package com.sample.remote
{
	import com.sample.Constants;
	import com.sample.command.SessionCommands;
	import com.sample.model.ModelLocator;
	import com.trg.flex.remote.ConnectionManager;
	
	import mx.binding.utils.ChangeWatcher;
	import mx.events.PropertyChangeEvent;

	public class MainConnectionManager extends ConnectionManager
	{
		public function MainConnectionManager() {
			super();
			id = "mainConnection";
			ChangeWatcher.watch(this, "authenticated", authenticatedChanged);
			
			connected = true;
		}
		
		private static var _instance:MainConnectionManager;
		
		public static function instance():MainConnectionManager {
			if (!_instance)
				_instance = new MainConnectionManager();
			return _instance;
		}
		
		private var model:ModelLocator = ModelLocator.getInstance();
		
		override public function authenticate():void {
			authenticated = false;
		}
		
		private function authenticatedChanged(event:PropertyChangeEvent):void {
			if (event.newValue == false && model.sessionState == Constants.SESSION_STATE_LOGGED_IN) {
				SessionCommands.i.refreshState();
			}
		}
		
	}
}